/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2019-2019.
 * Description: support getting gic type
 * Author: yanbo
 * Create: 2019-09-24
 */
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/hal/gic.h>
#include <linux/printk.h>

enum rtos_gic_type rtos_gic_type = RTOS_GIC_TYPE_NONE;

/* sync with rtos_gic_type */
static struct rtos_gic_type_info gic_type_info[] = {
	{
		.name = "TotemV1",
		.type_num = HISI_TOTEM_V1,
	}, {
		.name = "TotemV2",
		.type_num = HISI_TOTEM_V2,
	}, {
		.name = "SICV100",
		.type_num = HISI_SIC_V100,
	},
};

void get_gic_type(struct device_node *gic)
{
	const char *gic_type = NULL;
	struct rtos_gic_type_info *match = NULL;

	if (of_property_read_string(gic, "rtos-gic-type", &gic_type)) {
		rtos_gic_type = RTOS_GIC_TYPE_NONE;
		return;
	}

	for (match = gic_type_info; match < gic_type_info + ARRAY_SIZE(gic_type_info); match++) {
		if (strcmp(gic_type, match->name) == 0) {
			rtos_gic_type = match->type_num;
			pr_info("gic type %s\n", match->name);
			return;
		}
	}

	rtos_gic_type = RTOS_GIC_TYPE_NONE;
	pr_info("invalid gic type %s\n", gic_type);
}
